package com.addplus.townmall.server.api.mapper.town;

import com.addplus.townmall.server.api.model.town.ShopParticipateActive;
import com.addplus.townmall.server.api.model.town.expand.ShopParticipateExpand;
import com.addplus.townmall.server.api.utils.BaseAddMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * 商城商品状态类型关联表 Mapper 接口
 * </p>
 *
 * @author zhangjiehang
 * @since 2018-10-16
 */
public interface ShopParticipateActiveMapper extends BaseAddMapper<ShopParticipateActive> {

    @Select("SELECT\n" +
            " sas.shop_id as shop_product_id,\n" +
            " sas.id, \n" +
            " sas.shop_sku_id,\n" +
            " sas.sale_price,\n" +
            " sas.line_price,\n" +
            " sas.stock,\n" +
            " sas.limit_count,\n" +
            " sa.begin_date,\n" +
            " sa.end_date,\n" +
            " sa.`status`, \n" +
            " sa.`name` as spike_name \n" +
            "FROM\n" +
            " shop_participate_active a\n" +
            " LEFT JOIN spike_active sa ON sa.id = a.shop_obj_id \n" +
            " AND sa.is_deleted = 0 \n" +
            " AND sa.STATUS = 1\n" +
            " LEFT JOIN spike_active_shop sas ON sas.spike_active_id = sa.id \n" +
            " AND sas.is_deleted = 0 \n" +
            " AND sas.shop_id = a.shop_product_id \n" +
            " AND sas.shop_sku_id = a.shop_sku_id \n" +
            "WHERE\n" +
            " a.`status` = 1 \n" +
            " AND a.is_deleted = 0 \n" +
            " AND a.shop_product_id = #{shopProductId} \n" +
            " AND a.shop_sku_id = #{shopSkuId}\n" +
            "ORDER BY a.gmt_create desc\n" +
            "LIMIT 1")
    ShopParticipateExpand getSpikeActoveShopMessage(@Param("shopProductId") Integer shopProductId, @Param("shopSkuId") Integer shopSkuId);


    @Select("SELECT\n" +
            " s.shop_product_id,\n" +
            " s.id,\n" +
            " s.shop_sku_id,\n" +
            " s.sale_price,\n" +
            " s.line_price\n" +
            "FROM\n" +
            " shop_participate_active a\n" +
            " LEFT JOIN optimal_shop s ON a.shop_obj_id = s.id \n" +
            " AND s.shop_product_id = a.shop_product_id \n" +
            " AND s.shop_sku_id = a.shop_sku_id \n" +
            " AND s.is_delete = 0 \n" +
            "WHERE\n" +
            " a.`status` = 1 \n" +
            " AND a.is_deleted = 0 \n" +
            " AND a.shop_product_id = #{shopProductId} \n" +
            " AND a.shop_sku_id = #{shopSkuId}\n" +
            "ORDER BY a.gmt_create desc\n" +
            "LIMIT 1")
    ShopParticipateExpand getOptiomalShopMessage(@Param("shopProductId") Integer shopProductId, @Param("shopSkuId") Integer shopSkuId);


    @Select("SELECT\n" +
            " z.shop_product_id,\n" +
            " z.id,\n" +
            " z.shop_sku_id,\n" +
            " z.sale_price,\n" +
            " z.line_price,\n" +
            " z.limit_count \n" +
            "FROM\n" +
            " shop_participate_active a\n" +
            " LEFT JOIN shop_discount_zone z ON z.id = a.shop_obj_id \n" +
            " AND z.shop_product_id = a.shop_product_id \n" +
            " AND z.shop_sku_id = a.shop_sku_id \n" +
            " AND z.is_delete = 0 \n" +
            "WHERE\n" +
            " a.`status` = 1 \n" +
            " AND a.is_deleted = 0 \n" +
            " AND a.shop_product_id = #{shopProductId} \n" +
            " AND a.shop_sku_id = #{shopSkuId} \n" +
            "ORDER BY\n" +
            " a.gmt_create DESC \n" +
            " LIMIT 1")
    ShopParticipateExpand getDiscountZoneMessage(@Param("shopProductId") Integer shopProductId, @Param("shopSkuId") Integer shopSkuId);

}
